package com.dayuanit.atm.service;

import com.dayuanit.atm.entity.Transfer;
import com.dayuanit.atm.exception.BizException;
import com.dayuanit.atm.mapper.TransferMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TransferService {

    @Autowired
    private TransferMapper transferMapper;

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public void changeTransferStatus(Transfer transfer, int newStatus) {
        System.out.println(">>>>修改订单状态为2成功..................");
        //注意：前面事务的修改SQL如果和后面的事务修改同一行记录 可能会发生死锁。
        int rows = transferMapper.updateStatus(transfer.getId(), transfer.getStatus(), newStatus);
        System.out.println(">>>>修改订单状态为2成功------------------");
        if (rows != 1) {
            throw new BizException("修改转账订单失败");
        }


    }
}
